<template>
  <div>
    <el-table
      v-loading="loading"
      :data="dataList"
      height="500"
      style="width: 100%;
      margin-bottom: 20px;"
      border
    >
      <el-table-column :label="$t('日期')" prop="finDate" align="left" width="180" />
      <el-table-column :label="$t('凭证字号')" align="left" prop="voucherNum" width="120">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleDetailClick(scope.row)">{{ scope.row.voucherNum }}</el-button>
        </template>
      </el-table-column>
      <el-table-column :label="$t('科目')" align="left" prop="subjectName" />
      <el-table-column :label="$t('摘要')" align="left" prop="summary" show-overflow-tooltip />
      <el-table-column :label="$t('借方')" align="right" prop="debitAmount">
        <template slot-scope="scope">
          {{ formattedNumber(scope.row.debitAmount) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('贷方')" align="right" prop="creditAmount">
        <template slot-scope="scope">
          {{ formattedNumber(scope.row.creditAmount) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('方向')" align="right" prop="direction" />
      <el-table-column :label="$t('余额')" align="right" prop="balance">
        <template slot-scope="scope">
          {{ formattedNumber(scope.row.balance) }}
        </template>
      </el-table-column>
    </el-table>
    <el-dialog
      v-if="formOpen"
      v-el-drag-dialog
      :title="$t('明细账')"
      :visible.sync="formOpen"
      width="70%"
      :close-on-click-modal="false"
      :lock-scroll="false"
      custom-class="dialogForm voucherDialog"
      append-to-body
    >
      <voucherForm ref="voucherForm" :operate-type="operateType" />
    </el-dialog>
  </div>
</template>

<script>
import voucherForm from '../voucher/voucherForm.vue'
import {
  findSubjectDetail
} from '@/api/fin/report/finReport'
export default {
  components: {
    voucherForm
  },
  data() {
    return {
      dataList: [],
      loading: false,
      tempId: undefined,
      formOpen: false,
      operateType: 'view'
    }
  },
  created() {},
  methods: {
    // 初始化数据
    init(data) {
      console.log(data)
      this.loading = true
      findSubjectDetail(data).then(res => {
        this.dataList = res.data
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      // this.$parent.$parent.reset()
    },
    handleDetailClick(row) {
      row['yearMonth'] = row.finDate.substring(0, 7)
      this.formOpen = true
      this.$nextTick(() => {
        // 调用form页面的 init 方法初始化数据
        this.$refs.voucherForm.init(row)
      })
    }
  }
}
</script>
<style lang="scss" scoped>
/deep/.el-table__body  tr:first-child td {
  background-color: #f5f7fa;
}
</style>
